/**
 * 2007-12-22
 */
package com.ipay.utils;

import java.security.NoSuchAlgorithmException;

/**
 * @author JXB
 *
 */
public abstract class Encoder {
	private static final Encoder hex = new HexEncode();
	private static final Encoder base64 = new Base64();
	
	public static Encoder getInstance(String algorithm) throws NoSuchAlgorithmException {
		if ("hex".equals(algorithm)) return hex;
		else if ("base64".equals(algorithm)) return base64;
		throw new NoSuchAlgorithmException(algorithm);
	}

	public abstract String encode(byte[] data);
	
	public abstract byte[] decode(String str);
}
